package com.cssl.controller;

import com.cssl.pojo.Sms;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;
import org.json.JSONException;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping(value = "/sms")
public class SmsController {
    @RequestMapping(value = "ndCode",method = RequestMethod.POST)
    public  void  sms(@RequestBody Sms sms){
        int appid=1400645134;
        String appkey="020a94f19a97d01cf2c1bcb744a4fa6e";
        int templateId=1333465;
        String smsSign="BlackCat物流";
        try {
            String[] params={sms.getCode(),Integer.toString(sms.getMin())};
            SmsSingleSender ssender=new SmsSingleSender(appid,appkey);
            SmsSingleSenderResult result=ssender.sendWithParam("86",sms.getPhoneNumber(),
                    templateId,params,smsSign,"","");
        }catch(HTTPException e){
            e.printStackTrace();
        }catch (JSONException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}

